import { fly } from '@/utils/fly' 

const requestRouter = [
  { router: 'fortunetelling',url:'/fortunetelling/index'}, 
  { router: 'eightMarry',url:'/fortunetelling/bzhh'}, 
  { router: 'nameTest',url:'/fortunetelling/theNameTest'}, 
  { router: 'fengshuiType',url:'/fortunetelling/fengshuiArticleMType'}, 
  { router: 'fengshuiCType',url:'/fortunetelling/fengshuiArticleCType'}, 
  { router: 'fengshuiContent',url:'/fortunetelling/fengshuiArticleContent'}, 
  { router: 'zodiacLuck',url:'/fortunetelling/zodiacLuck'},
  { router: 'chouQian', url: '/fortunetelling/chouQian'}, // 抽签
  { router: 'channelDiscountCoupon', url: '/fortunetelling/channelDiscountCoupon'}, //优惠券列表
  { router: 'discountCoupon', url:'/fortunetelling/discountCoupon'}, //领优惠券:dcid
  { router: 'findDiscountCoupon', url: '/fortunetelling/findDiscountCoupon'}, // 我的优惠券:status
  { router: 'comment', url: '/fortunetelling/comment'}, // 评论：productId，comment
  { router: 'commentRoll',url: '/fortunetelling/commentRoll'}, // 评论
  { router: 'orderById',url: '/order/id'}, // 评论
]

let getUrl = function(router) {
  let url =''
  requestRouter.forEach(element => {
    if (element.router === router) return url = element.url
  })
  return url
}

export default function(router, data={},method) {
	return new Promise((resolve,reject) => {
    if (method.toLowerCase()=='get') {
      fly.get(getUrl(router), data).then(res => {
        resolve(res)
      }, err => {
        reject(err)
      })
    } else {
      fly.post(getUrl(router), data).then(res => {
        resolve(res)
      }, err => {
        reject(err)
      })
    }
	})
}